package com.songlanyun.modules.goods.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ResourceBundle;

@Configuration
@PropertySource(value = {"classpath:goodsCategoryMap.properties"}, encoding = "UTF-8")
public class GoodsCategoryConfig {

    static  {
        // 读取resources目录下的goodsCategoryMap.properties
        ResourceBundle rb2 = ResourceBundle.getBundle("goodsCategoryMap");
        for(String houniaoCategoryIdPath : rb2.keySet()){
            String huixuanCategoryIdText = rb2.getString(houniaoCategoryIdPath);
            Long huixuanCategoryIdValue = Long.parseLong(huixuanCategoryIdText);
            SingletonHolder.goodsCategoryMap.put(houniaoCategoryIdPath, huixuanCategoryIdValue);
        }
    }

    private static class SingletonHolder {

        private static GoodsCategoryConfig instance = new GoodsCategoryConfig();

        public static final Map<String, Long> goodsCategoryMap = new LinkedHashMap<>();
    }

    public static GoodsCategoryConfig getInstance() {
        return SingletonHolder.instance;
    }

    public static Map<String, Long> getGoodsCategoryMap() {
        return Collections.unmodifiableMap(SingletonHolder.goodsCategoryMap);
    }
}
